package ano.it.controller;

import ano.it.constant.MessageConstant;
import ano.it.entity.PageResult;
import ano.it.entity.QueryPageBean;
import ano.it.entity.Result;
import ano.it.pojo.Permission;
import ano.it.pojo.Role;
import ano.it.service.PermissionService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Reference
    private PermissionService permissionService;
    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Permission> devices=permissionService.findAll();
            return new Result(true, MessageConstant.QUERY_DATA_SUCCESS,devices);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_DATA_FAIL);
        }

    }
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult=permissionService.findPage(queryPageBean);
        return pageResult;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){
        System.out.println("gsdgdsg"+permission);
        try {
            permissionService.add(permission);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_POWER_FAIL);
        }
        return new Result(true,MessageConstant.ADD_POWER_SUCCESS);
    }
}
